package hui.zhang.mq;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Service;

import hui.zhang.utils.SmsUtils;


@Service("smsConsumer")
public class SmsConsumer implements MessageListener {

	@Override
	public void onMessage(Message message) {
		try {
			MapMessage mapMessage = (MapMessage) message;
			//Integer code = SmsUtils.sendSms(mapMessage.getString("telephone"));
			Integer code = SmsUtils.sendSms(mapMessage.getString("telephone"), mapMessage.getInt("mobile_code"));
			//int code = mapMessage.getInt("mobile_code");
			System.out.println(mapMessage.getString("telephone"));
			if(code!=0000) {
				System.out.println("短信发送成功！");
			//mapMessage.getString("telephone");
			}
		} catch (Exception e) {
			throw new RuntimeException("短信发送失败！",e);
		}

	}
}
